<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/11/8
  Time: 21:12
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="fm" %>
<script src="webjars/jquery/3.1.1/jquery.min.js" charset="utf-8"></script>
<html>
<head>
    <style type="text/css">
        * {
            margin: 0 auto;
            margin-top: 20px;
            text-align: center;
        }
        #list tr:nth-of-type(odd){ background:#68605E;}
    </style>
    <title>航班查询</title>
</head>
<body>
<h1>航班查询页面</h1>
<div>
    <form id="form1" action="/getCity" method="get">
        <span>起飞城市：</span>
        <select name="ago" style="height: 25px;  color: #64696c;"><!-- width: 150px; -->
            <OPTION value="0">--请选择起飞城市--</OPTION>
            <c:forEach items="${city}" var="c">
                <option ${departureCity==c.id?'selected':''} value="${c.id}">${c.cityName}</option>
            </c:forEach>
        </select>
        <span>————</span>
        <span>到达城市：</span>
        <select name="arrive" style="height: 25px;  color: #64696c;"><!-- width: 150px; -->
            <OPTION value="0">--请选择起飞城市--</OPTION>
            <c:forEach items="${city}" var="c">
                <option ${arrivalCity==c.id?'selected':''} value="${c.id}">${c.cityName}</option>
            </c:forEach>
        </select>
        <input type="button" value="查询" onclick="getSelect()">
    </form>
    <c:if test="${flight.size() > 0}">
        <h3>帮你查找到以下航班</h3>
        <table id="list" border="1">
            <tr>
                <th>航班编号</th>
                <th>起飞城市</th>
                <th>起飞时间</th>
                <th>到达城市</th>
                <th>到达时间</th>
            </tr>
            <c:forEach items="${flight}" var="f">
                <tr>
                    <td>${f.flightNo}</td>
                    <td>${f.cityName}</td>
                    <td><fmt:formatDate value="${f.departureTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                    <td>${f.CName}</td>
                    <td><fmt:formatDate value="${f.arrivalTime}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                </tr>
            </c:forEach>
        </table>
    </c:if>
    <c:if test="${flight.size() == 0}">
        <h3>没有找到符合条件的航班，请改变查询条件重试</h3>
    </c:if>
</div>

</body>
</html>
<script type="text/javascript">
    function getSelect() {
        var ago = $("select[name=ago]").val();
        var arrive = $("select[name=arrive]").val();
        if (ago == 0) {
            alert("请选择起飞城市");
        } else if (arrive == 0) {
            alert("请选择到达城市");
        } else if (ago == arrive) {
            alert("起飞城市和到达城市不能相同");
        } else {
            document.getElementById("form1").submit()
        }
    }
</script>
